﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using secondhand.L3object;
using System.Data;
using secondhand.L1database;

namespace secondhand.L2busslogic
{
    public class userBL
    {
        public static userOB Getmark()     //获取数据库中的大单条数据
        {
            string commandtext = "select * from yonghu ";
            userOB myword = new userOB();       //数据库对象
            myword.user_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = userDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;

            myword.user_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.pass_word = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.user_num = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.user_mail = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.user_count = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.freeze_count = ds.Tables[0].Rows[i][6].ToString().Trim();
            myword.usable_count = ds.Tables[0].Rows[i][7].ToString().Trim();
            return myword;
        }
        public static userOBList GetmarkAll()       //获取数据库中的所有记录
        {
            string commandtext = "select * from yonghu";
            userOBList tempList = null;
            tempList = new userOBList();
            DataSet ds = null;
            ds = userDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                userOB myword = new userOB();

                myword.user_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.pass_word = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.user_num = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.user_mail = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.user_count = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.freeze_count = ds.Tables[0].Rows[i][6].ToString().Trim();
                myword.usable_count = ds.Tables[0].Rows[i][7].ToString().Trim();
                tempList.Insert(i, myword);
            }
            return tempList;
        }
        public static bool Addfill(userOB myword)      //添加纪录
        {
            string ss = "INSERT INTO yonghu (user_name,pass_word,user_num,user_mail,user_count,freeze_count,usable_count)VALUES('";
            ss = ss + myword.user_name.Trim() + "','";
            ss = ss + myword.pass_word.Trim() + "','";
            ss = ss + myword.user_num.Trim() + "','";
            ss = ss + myword.user_mail.Trim() + "','";
            ss = ss + myword.user_count.Trim() + "','";
            ss = ss + myword.freeze_count.Trim() + "','";
            ss = ss + myword.usable_count.Trim() + "')";
            return userDB.AddDeleteItem(ss);
        }

        public static userOB Getwordsingle(string nameq)      //按姓名查找
        {
            string commandtext = "select * from yonghu where user_name='" + nameq.Trim() + "'";
            userOB myword = new userOB();
            myword.user_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = userDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;

            myword.ID = ds.Tables[0].Rows[i][0].ToString().Trim();
            myword.user_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.pass_word = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.user_num = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.user_mail = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.user_count = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.freeze_count = ds.Tables[0].Rows[i][6].ToString().Trim();
            myword.usable_count = ds.Tables[0].Rows[i][7].ToString().Trim();
            return myword;
        }
        public static bool Savemark(userOB myword)     //修改记录
        {
            string commandtext = "update yonghu set  user_name='";
            commandtext = commandtext + myword.user_name.Trim() + "', pass_word='";
            commandtext = commandtext + myword.pass_word.Trim() + "', user_num='";
            commandtext = commandtext + myword.user_num.Trim() + "', user_mail='";
            commandtext = commandtext + myword.user_mail.Trim() + "',user_count='";
            commandtext = commandtext + myword.user_count.Trim() + "',freeze_count='";
            commandtext = commandtext + myword.freeze_count.Trim() + "',usable_count='";
            commandtext = commandtext + myword.usable_count.Trim() + "' where ID=";
            commandtext = commandtext + myword.ID.Trim();
            return userDB.AddDeleteItem(commandtext);
        }
        public static bool deleteword(string name)      //删除记录
        {

            string ss = "delete from yonghu where user_name='" + name.Trim() + "'";
            return userDB.AddDeleteItem(ss);


        }
    }
}